/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package l1j.jrwz.server.serverpackets;

import l1j.jrwz.server.Opcodes;
import l1j.jrwz.server.model.L1Character;
import l1j.jrwz.server.model.Instance.L1NpcInstance;

/**
 * Class <code>S_PetCtrlMenu</code> 图形控制界面(宠物or召唤物).
 * 
 * @author jrwz
 * @version 2012-12-3下午5:15:44
 * @see l1j.jrwz.server.serverpackets
 * @since JDK1.7
 */
public class S_PetCtrlMenu extends ServerBasePacket {
    private static final String _S_PET_CTRL_MENU = "[S] S_PetCtrlMenu";
    private byte[] _byte = null;

    /**
     * 图形控制界面(宠物or召唤物).
     * 
     * @param cha
     *            - 对象(主人)
     * @param npc
     *            - 宠物or召唤物
     * @param flag
     *            - True：显示、False：关闭
     */
    public S_PetCtrlMenu(L1Character cha, L1NpcInstance npc, boolean flag) {
        writeC(Opcodes.S_OPCODE_PETCTRL);
        writeC(0x0c);
        if (flag) {
            writeH(0x03);
            writeD(0x00000000);
            writeD(npc.getId());
            writeD(0x00000000);
            // writeH(0x0000);
            writeH(npc.getX());
            writeH(npc.getY());
            writeS(npc.getName());
        } else {
            writeH(0x0000);
            writeD(0x00000001);
            writeD(npc.getId());
            writeS(null);
        }
    }

    @Override
    public byte[] getContent() {
        if (_byte == null) {
            _byte = getBytes();
        }
        return _byte;
    }

    @Override
    public String getType() {
        return _S_PET_CTRL_MENU;
    }
    // @Override
    // public byte[] getContent() {
    // return this.getBytes();
    // }

}
